<?php
/**
 * Created by PhpStorm.
 * User: 10838
 * Date: 2017/11/3
 * Time: 10:56
 */

class Message{
    private $un = ""; //用户名
    private $pw = ""; //密码
    private $da = ""; //手机号
    private $sm = ""; //内容
    private $dc = ""; //消息编码
    private $sa = ""; //扩展号
    private $st = ""; //定时时间
    private $tf = ""; //内容编码格式
    private $rd = ""; //是否报告
    private $rf = ""; //返回格式

    public function __construct()
    {
        set_phone($this->un,$this->pw,$this->da,$this->sm,$this->dc,$this->sa,$this->st,$this->tf,$this->rd,$this->rf);
    }
    public function set_phone($un,$pw,$da,$sm,$dc,$sa,$st,$tf,$rd,$rf)
    {
        header("Content-type: text/html; charset=utf-8");
        date_default_timezone_set('PRC'); //设置默认时区为北京时间
        $url = "http://IP+Port/mt?";//地址
        switch ($tf) {
            case 0://HEX十六进制
                $sm = iconv("UTF-8", "GB2312//IGNORE", $sm);
                $sm = bin2hex($sm);
                break;
            case 1://Base64
                $sm = iconv("UTF-8", "GB2312//IGNORE", $sm);
                $sm = base64_encode($sm);
                break;
            case 2://URLEncode
                $sm = rawurlencode(mb_convert_encoding($sm, "gb2312", "utf-8"));
                break;
            case 3://URLEncode+UTF8
                $sm = urlencode($sm);
                break;
            default:
                echo "无法识别";
        }
    }
    public function get_code(){
        //post
        $url = "http://IP+Port/mt?";
        $curpost = "un=".$this->un."&pw=".$this->pw."&da=".$this->da."&sm=".$this->sm."&dc=".$this->dc."&sa=".$this->sa."&st=".$this->st."&tf=".$this->tf."&rd=".$this->rd."&rf=".$this->rf;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curpost);
        $result = curl_exec($ch);
        curl_close($ch);
        echo("<br>");
        echo('<table class="XS"><tr><td>');
        echo($url.$curpost);
        echo("<br>");
        echo($result);
        echo('</td></tr></table>');
    }
}